package com.ctg.itrdc.sysmgr.permission.core.utils;


import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

import com.ctg.itrdc.sysmgr.permission.core.CtgUser;

public class WebUtils extends org.apache.shiro.web.util.WebUtils {

	/**
	 * 判断ajax请求
	 * 
	 * @param request
	 * @return
	 */
	public static boolean isAjax(HttpServletRequest request) {
		return (request.getHeader("accept") != null && request.getHeader("accept").contains("application/json"))
				|| (request.getHeader("X-Requested-With") != null
						&& "XMLHttpRequest".equals(request.getHeader("X-Requested-With").toString()));
	}

	public static CtgUser getCtgUser() {
		Subject subject = SecurityUtils.getSubject();
		Object principal = subject.getPrincipal();
		if (principal == null) {
			return null;
		}
		CtgUser shiroUser = (CtgUser) principal;
		return shiroUser;
	}
}
